//
//  ViewController.swift
//  SKClock
//
//  Created by Sky-work on 2021/12/21.
//

import UIKit

class ViewController: UIViewController {
    
    private var timer: Timer!
    private var count = 0

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
//        
        view.backgroundColor = UIColor.blue
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        super.touchesBegan(touches, with: event)
        
        testProxy()
    }
    
    
    private func testProxy() {
        let proxy = SKProxy.proxy(self)
        timer = Timer.scheduledTimer(timeInterval: 1, target: proxy, selector: #selector(testAction), userInfo: nil, repeats: true)
        count = 0
    }
    
    @objc private func testAction() {
        count += 1
        print("哈哈哈哈哈 _", #function, #line, count)
    }
    
    
    private func invalidateTimer() {
        if timer != nil {
            timer.invalidate()
            timer = nil
        }
        count = 0
        print("timer did invalidate!")
    }
    
    deinit {
        invalidateTimer()
        
        print("deinit", #line)
    }
}

